package model.mediators;

import java.util.Iterator;
import java.util.List;

import model.area_effect.Interactable;
import model.area_effect.MapAreaOfEffect;
import model.area_effect.SkillObject;
import model.area_effect.Trap;
import model.entity.Entity;
import model.item.InventoryItem;
import model.item.MapGold;
import model.map.GameMap;
import model.map.MapPoint;


/**
 * This class is responsible for handling anything that might collide with an entity when it is sitting on a tile.
 * This includes items, gold, skills, abilities, and traps. During entity's update() method, it will collide with
 * everything on the tile that it resides on.
 * @author Drew
 *
 */
public class CollisionMediator extends MapMediator {

	public static void collide(Entity entity) {
		GameMap gameMap = MapMediator.getMap();
		MapPoint entityLocation = entity.getLocation();
		List<InventoryItem> itemList = gameMap.getInventoryItemsOnTile(entityLocation);
		
		List<Interactable> interactables = gameMap.getInteractablesOnTile(entityLocation);
		
		List<MapGold> mapGoldList = gameMap.getMapGoldOnTile(entityLocation);
		
		for (InventoryItem item : itemList) {
			gameMap.removeItemFromTile(item, entityLocation);
			entity.pickUpItem(item);
		}
		
		for(Interactable i : interactables)
			i.interact(entity);
		
		for (MapGold gold : mapGoldList) {
			gameMap.removeMapGoldFromTile(gold, entityLocation);
			entity.pickUpGold(gold);
		}
	}
}
